// hello.cc
#include <node.h>
#include <v8.h>

using namespace v8;

namespace demo {

using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;

void Method(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();
  args.GetReturnValue().Set(String::NewFromUtf8(
      isolate, "world").ToLocalChecked());
}
static void RunCallback(const FunctionCallbackInfo<Value>& args) {
  Isolate* isolate = args.GetIsolate();
  Local<Context> context = isolate->GetCurrentContext();  
  
  Local<Function> cb = Local<Function>::Cast(args[0]); 
  
  const unsigned argc = 1;
  Local<Value> argv[argc] = {
	  String::NewFromUtf8(isolate, "hello world!!!", NewStringType::kNormal).ToLocalChecked() 
  };
  cb->Call(context, Null(isolate), argc, argv).ToLocalChecked();
}

void Initialize(Local<Object> exports) {
  NODE_SET_METHOD(exports, "hello", Method);
  NODE_SET_METHOD(exports, "callback", RunCallback);

}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)

}  // 命名空间示例